package com.wkq.net.interceptor

import android.util.Log
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import java.io.IOException

class LoggingInterceptor : Interceptor {
    var TAG: String = "RetrofitRequestHelper:"

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val request: Request = chain.request()
        Log.d(TAG, "--url-:" + request.url)
        Log.d(TAG, "--request--:$request")
        val response: Response = chain.proceed(chain.request())
        val mediaType = response.body!!.contentType()
        val content = response.body!!.string()
        Log.d(TAG, "--$TAG---response----->:$content")
        return response.newBuilder().body(content.toResponseBody(mediaType)).build()
    }
}